// pages/user/user.js
let app=getApp();
Page({
    // 页面的初始数据
    data: {
    imagurl:'',
    username:''
    },
    
//跳转到个人信息页面
goinfo()
{
    wx.navigateTo({
      url: '/pages/info/info',
    })
},
 onShow:function(){
  if(app.globalData.openid==""||app.globalData.openid==null||app.globalData.openid==undefined)
  {
    this.gologin();
  }
  else{
    this.gettouxiang();
    this.setData({
      username:app.globalData.username
    })
  }
 },

      //未登录跳转到登录界面
      gologin()
      {
             wx.redirectTo({
               url: '/pages/login/login',
             })

    },
    //跳转相册
    goxiangce()
    {
      wx.navigateTo({
        url: '/pages/xiangce/xiangce',
      })

    },
    PreviewImg(){
      let imglist=[];
      imglist.push(this.data.imagurl);
      wx.previewImage({
        current: imglist[0],
        urls:imglist,
      })
      },
      //退出操作
      exitzhanghu()
      {
        wx.clearStorage();
        for(let key in app.globalData)
        {
          if(key!="url")
          {
            app.globalData[key]=null;
          }
        }
        wx.switchTab({
          url: '/pages/current/current',
        });
      },
      gettouxiang()
      {
        let that=this;
        wx.request({
          url:app.globalData.url+'/getAvstar', 
          header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
          data: {
              openid:app.globalData.openid,
           },
           method: 'post',
           success: function (res) {
                that.setData({
                  imagurl:res.data.avstar
                })
                wx.setStorageSync('touxiang', res.data.avstar);
                app.globalData.touxiang=res.data.avstar;
           },
           fail:function(err){//请求失败之后要做什么
              console.log('请求失败')
              }  
      })
      }
})